package com.zsx.shopping.common.api;

import com.zsx.shopping.common.enums.CodeMsg;
import lombok.Data;

// 方法应尽量不与其他类绑定,内部实现无所谓

@Data
public class R<T> {

    private Integer code;

    private String msg;

    private T data;

    private R(){}

    public static <T> R<T> success() {
        R<T> r = new R<>();
        CodeMsg success = CodeMsg.SUCCESS;
        r.setCode(success.getCode());
        r.setMsg(success.getMsg());
        return r;
    }

    public static <T> R<T> success(T data) {
        R<T> r = new R<>();
        CodeMsg success = CodeMsg.SUCCESS;
        r.setCode(success.getCode());
        r.setMsg(success.getMsg());
        r.setData(data);
        return r;
    }

    public static <T> R<T> fail(Integer code, String msg) {
        R<T> r = new R<>();
        r.setCode(code);
        r.setMsg(msg);
        return r;
    }
}
